<?php
/**
 * @Desc 首页
 * @Auth Menory
 * @Date 2016年3月7日 13:59:20
 */
namespace Act\Menus;
use Act\Base;

class addMenuGroup extends Base {
    /**
     * 显示添加菜单分组页面
     * @return  Void
     */
    public function doGet() {
        $subNav = [
            ['title'=>'菜单查询', 'url'=>'/menus/adminMenuList'],
            ['title'=>'添加菜单', 'url'=>'/menus/addMenu'],
            ['title'=>'菜单分组', 'url'=>'/menus/admGroup'],
            ['title'=>'添加分组', 'url'=>'#', 'active'=>true],
        ];
        $this->setTemplateNav('后台菜单', $subNav);
        $this->display('index.php');
    }

    /**
     * 添加分组
     * @return Void
     */
    public function doPost() {
        $name = post('name');
        $type = post('type');
        $icon = post('icon', 'pure-menu-item');

        if (!check_not_empty($name, $type))
            return $this->error("缺少必选项", '', 2);

        $MGroupModel = model('MenuGroup');
        $isExist = $MGroupModel->isExistGroup($name);
        if ($isExist !== false)
            return $this->error('分组已存在', '', 2);

        $moduleId = $MGroupModel->addMenuGroup(['name' => $name, 'type' => $type, 'icon' => $icon]);
        if ($moduleId !== false)
            $this->success('分组添加成功', '/menus/adminMenuList', 2);
        else 
            $this->error('分组添加失败', '', 2);
    }

}